import java.beans.IntrospectionException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import CalculateSystem.CalculateMain;
import SpaceDebug.DebugTool.DebugTool;
import SpaceDebug.Factory.IOSystemFactory.IOFactory;
import SpaceDebug.IOTool.IOTool;
import SpaceDebug.IOTool.Read.ReadType;
import SpaceDebug.IOTool.Write.WriteType;
import SpaceDebug.Test.TestData;

public class App {
    public static void main(String[] args) throws Exception {
        MoreWiter();
    }

    private static void Calculate() throws Exception {
        CalculateMain calculateMain = new CalculateMain();
        while (true) {
            System.err.println(calculateMain.Input());
        }
    }

    private static void MoreWiter() throws Exception {
        TestData test = new TestData(11, "王明");
        IOTool newTool = IOFactory.Instance.GetIOTool(WriteType.DebugMassage);
        DebugTool newDebugTool = new DebugTool(newTool);
        newDebugTool.Info(test);
        // or: newDebugTool.setIOTool(IOFactory.Instance.GetIOTool(WriteType.Cool));
        newTool.SetWriteTool(WriteType.Cool);
        newDebugTool.Info(test);
    }

    /**
     * 测试序列化和反序列化工具
     * 
     * @throws Exception
     */
    private static void SerilizaTest() throws Exception {
        String path = "./SpaceDebugHelper/DebuggerFile/test.txt";
        TestData test = new TestData(11, "王明");
        IOTool ioTool = IOFactory.Instance.GetIOTool(ReadType.SPACE, WriteType.SPACE);
        ioTool.Write(path, test);

        System.err.println(ioTool.Translate(test));

        TestData test2 = new TestData(99, "李华");
        System.err.println(ioTool.Translate(test2));
        ioTool.Read(path, test2);
        System.err.println(ioTool.Translate(test2));
    }

    /**
     * FuncA用来测试工具对数据的输出
     */
    private static void FuncA() throws Exception {
        TestData test = new TestData(30, "耶耶耶");
        FuncB(test);
    }

    private static void FuncB(TestData data) throws Exception {
        DebugTool newDebugTool = new DebugTool();
        newDebugTool.Error(data);
    }

    private static void IOToolTestTran() {
        IOTool testIoTool = IOFactory.Instance.GetIOTool(ReadType.SPACE, WriteType.SPACE);
        TestData newData = new TestData(32, "小明");
        testIoTool.Write("./SpaceDebugHelper/DebuggerFile/test.txt", newData);
    }

    private static void IOToolTestBack() throws IllegalAccessException, InvocationTargetException,
            NoSuchMethodException, SecurityException, IOException, IntrospectionException {
        IOTool testIoTool = IOFactory.Instance.GetIOTool(ReadType.SPACE, WriteType.SPACE);
        TestData newData = new TestData(66, "老王");
        System.err.println(newData.toString());
        testIoTool.Read("./SpaceDebugHelper/DebuggerFile/test.txt", newData);
        System.err.println(newData.toString());
    }

}
